<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<div class="docs-main">
    <?php ActiveForm::begin(); ?>
    <table id="tablesaw" class="tablesaw table yx-table1 yx-table3 table-striped with-check" >
        <thead>
        <tr class="yx-bgd2f6ec">
            <th><span class="yx-star">*</span><?= \Yii::t('zhtfrontend', '金额'); ?></th>
            <th><span class="yx-star">*</span><?= \Yii::t('zhtfrontend', '备注'); ?></th>
            <th><?= \Yii::t('zhtfrontend', '操作'); ?></th>
        </tr>
        </thead>
        <?php if($data != null) { ?>
              <?php foreach ($data as $item) { ?>
                <tr>
                    <td><?=Html::textInput('money[]',$item->money,['class'=>'input-text','style'=>'width:50px'])?></td>
                    <td><?=Html::textInput('remark[]',$item->remark,['class'=>'input-text'])?></td>
                    <td><?=Html::hiddenInput('ids[]',$item->id)?><?=Html::buttonInput('移除',['class'=>'removeRow'])?></td>
                </tr>
              <?php } ?>
        <?php } ?>
            <tr>
                <td><?=Html::textInput('money[]',null,['class'=>'input-text','style'=>'width:50px'])?></td>
                <td><?=Html::textInput('remark[]',null,['class'=>'input-text'])?></td>
                <td><?=Html::hiddenInput('ids[]',null)?><?=Html::buttonInput('新增',['id'=>'addRow'])?></td>
            </tr>
        <div style="display: none"><?= Html::submitButton('保存', ['id'=>'dosubmit','class'=>"btn yx-save yx-radius50"]) ?></div>

    </table>
    <?php ActiveForm::end(); ?>
  </div>
<?php
$js = <<<JS
    $(document).on('click','#addRow',function(){
        var parents = $(this).parents('tr');
        var str = '<tr>';
            str += '<td><input type="text" class="input-text" name="money[]" style="width:50px"></td>';
            str += '<td><input type="text" class="input-text" name="remark[]"></td>';
            str += '<td><input type="hidden" name="ids[]" value="0" ><input type="button" class="removeRow" value="移除"></td>';
         parents.before(str);   
    });
   $(document).on('click','.removeRow',function(){
       $(this).parents('tr').remove();
   });
JS;
\Yii::$app->view->registerJs($js);
?>
